﻿using System.Collections;

namespace Pap.Web.Modules.Reports.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    using Pap.Core.Utilities;
    using Pap.Data;
    using Pap.Web.Utils;

    /// <summary>
    /// 
    /// </summary>
    public class UnionStatusReportViewModel : IViewModel
    {
        #region [ Fields ]

        IAdministrationRepository _AdminRepository;

        /// <summary>
        /// 
        /// </summary>
        IReportRepository _ReportRepository;

        #endregion Fields

        #region  [ Constructors ]

        /// <summary>
        /// Initializes a new instance of the <see cref="UnionStatusReportViewModel"/> class.
        /// </summary>
        /// <param name="repo">The repo.</param>
        public UnionStatusReportViewModel(IReportRepository repo, IAdministrationRepository adminRepo)
        {
            _ReportRepository = repo;
            _AdminRepository = adminRepo;
        }

        #endregion

        #region [ Methods ]

        /// <summary>
        /// Gets all projects.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<IProject> GetAllProjects()
        {
            return _AdminRepository.GetUserProjects(RegistryInfo.UserID);
        }

        /// <summary>
        /// Gets the union status report.
        /// </summary>
        /// <param name="projects">The projects.</param>
        /// <param name="fromDate">From date.</param>
        /// <param name="toDate">To date.</param>
        /// <returns></returns>
        //TODO: implement it as View
        public IEnumerable GetUnionStatusReport(List<Guid> projects, DateTime? fromDate, DateTime? toDate)
        {
            return new[]
            {
                new KeyValuePair<string, string>("allRequestsLoans", _ReportRepository.GetUnionStatusCountOfRequests(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("acceptedLoans" , _ReportRepository.GetUnionStatusCountOfAcceptedLoan(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("refusedLoans" , _ReportRepository.GetUnionStatusCountOfrefusedLoan(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("executedLoans" , _ReportRepository.GetUnionStatusCountOfLoanExecuted(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("stoppedLoans" , _ReportRepository.GetUnionStatusCountOfLoanStoppedFromExecution(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("totalAmountOfExecutedLoans" , _ReportRepository.GetUnionStatusTotalAmountOfExecutedLoans(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("totalOfRepaymentWithoutFines" , _ReportRepository.GetUnionStatusTotalOfRepaymentWithoutFines(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("totalAmountOfSpentInThisPeriod" , _ReportRepository.GetUnionStatusTotalAmountOfSpent(projects, fromDate, toDate).ToString()),                
                new KeyValuePair<string, string>("totalDueAmountinThisPeriod" , _ReportRepository.GetUnionStatusTotalDueAmount(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("fundingFromPap" , _ReportRepository.GetUnionStatusTheFundingFromPAP(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("totalFinesCollected" , _ReportRepository.GetUnionStatusTotalFinesCollected(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("terminatedPaymentLoans" , _ReportRepository.GetUnionStatusCountOfTerminatedPaymentLoans(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("benefitsRepayed" , _ReportRepository.GetUnionStatusTheBenefitsRepayed(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("loansTransferedToCourt" , _ReportRepository.GetUnionStatusCountOfLoansTransferedToCourt(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("repaymentPercentage" , _ReportRepository.GetUnionStatusRepaymentPercentage(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("primaryLoans" , _ReportRepository.GetUnionStatusCountOfPrimaryLoans(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("secondaryLoans" , _ReportRepository.GetUnionStatusCountOfSecondaryLoans(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("loansThatExceedTheThreeStage" , _ReportRepository.GetUnionStatusCountOfLoansThatExceedTheThreeStage(projects, fromDate, toDate).ToString()),
                new KeyValuePair<string, string>("renewalLoans" , _ReportRepository.GetUnionStatusCountOfRenewalLoans(projects, fromDate, toDate).ToString())
        };
        }

        #endregion Methods
    }
}